<template>
  <div class="page">

    <MCard :type="type" :cards="cards"></MCard>

    <div class="none" v-if="cards.length==0">
      <img src="../../../static/images/exchange/none.png" alt="">
    </div>
  </div>
</template>

<script>
import MCard from '../../components/MCard.vue'
export default {
  data () {
    return {
      type: '兑换',
      cards: [],
      openid: ''
    }
  },
  components: {
    MCard
  },

  mounted () {
    this.openid = wx.getStorageSync('openid')
    this.getexchangeHistory()
  },

  methods: {
    getexchangeHistory () {
      this.$http.get('/api/v1/score/exchange/history?openid=' + this.openid).then(res => {
        if (res.data.code === '0') {
          for (let item of res.data.data) {
            item.point = item.deduction_score
            item.date = item.deduction_time
            item.name = item.good_name
            item.img = item.good_image_src
          }
          this.cards = res.data.data
        } else {
          // 签到失败
          console.log('商品列表失败')
        }
      })
    }
  }
}
</script>

<style scoped>
.none {
  text-align: center;
  margin-top: 240rpx;
}
.none img {
  height: 170rpx;
  width: 533rpx;
}
</style>
<style>
page {
  background: #f1f1f1;
}
</style>